package com.example.miscontactos;

import com.example.miscontactos.Entidades.NombreAccion;
import android.os.Bundle;
import android.app.ListActivity;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class TabMails extends ListActivity 
{
	private static String CONTACTO_ID = "contactoId";
	private long contactoId = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_tab_mails);
		
		contactoId = this.getIntent().getExtras().getLong(CONTACTO_ID);
        Bundle b = this.getIntent().getExtras();
        
        contactoId = b.getLong(CONTACTO_ID);
        String mail_data[] = new String[b.size() - 1];
        
        if (b != null)
		{
			for (int i = 0; i < b.size() - 1; i ++)
			{
				mail_data[i] = b.getString(String.valueOf(i));
			}
			
			if(mail_data.length >= 1)
				setListAdapter(new ArrayAdapter(this,  android.R.layout.simple_list_item_1, mail_data));
			else
			{
				String[] values = new String[] { getResources().getString (R.string.contacto_sin_mail) };
				ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
						  android.R.layout.simple_list_item_1, android.R.id.text1, values);
				setListAdapter(adapter);
			}
		}
                
        
	}
	
	@Override
    protected void onListItemClick(ListView l, View v, int position, long id)
    {
		Object selectedMail = (String) getListAdapter().getItem(position);
		String mail = selectedMail.toString();
		AccionesUtilities.MandarEmail(TabMails.this, String.valueOf(contactoId), "", mail, "", NombreAccion.Llamada, "");
    }

	/*@Override
	public boolean onCreateOptionsMenu(Menu menu) 
	{
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_tab_mails, menu);
		return true;
	}*/
	

}
